var EventProxy = require('eventproxy');
var Icd = require('../models/icd.js');

module.exports = function(){
    var obj = new EventProxy();
    var queue = [];

    obj.bind("event", function() {
        if(queue.length === 0) return;



        Icd.create(collection,cd_create,function(err,doc){
            console.log("----------123");
            obj.trigger("event2");
        });
    });

    this.enqueue = function(type,func,data){
        var newEvent = {
            type : type,
            func : func,
            data : data
        };
        queue.push(newEvent);
    }
    /*
    var collection = "icd-cd";
    var cd_get = {
        user    : "user_test12",
        ccd_id  : "ccd_id_test"
    };
    var cd_create = {
        user: "user_test13",
        ccd_id: "ccd_id_test",
        cd : "cd_test"
    };

    obj.bind("event1", function(data,func) {
        Icd.create(collection,cd_create,function(err,doc){
            console.log("----------123");
            obj.trigger("event2");
        });
    });

    obj.bind("event2", function(data,func) {
        Icd.get(collection,cd_get,function(err,doc){
            console.log("-----------213");
            console.log(err);
            console.log(doc);
        });
    });

    this.test = function(){
        console.log("testInit");
        obj.trigger("event1");
    };
    */
};